#include<stdlib.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#define SEV_PORT 9999

int main(int argc,char **argv){

   char buf[BUFSIZ];
   char cbuf[BUFSIZ];

   struct sockaddr_in server_addr,client_addr;
   socklen_t client_socket_len;
   int sfd = socket(AF_INET,SOCK_STREAM,0);
   char serverip[] = "127.0.0.1";
   char clientip[64];
   server_addr.sin_family = AF_INET;
   server_addr.sin_addr.s_addr = inet_addr(serverip);
   server_addr.sin_port = htons(SEV_PORT);

   int bfd = bind(sfd,(struct sockaddr *)&server_addr,sizeof(server_addr));
   if (bfd == -1)
   {
    perror("bind is error");
    exit(1);
   }

   listen(sfd,1024);
   printf("server is started...\n");
   printf("server ip is:%s port is: %d\n",serverip,SEV_PORT);
   fflush(NULL);
   

   client_socket_len = sizeof(client_addr);
//    int ret = accept(sfd, (struct sockaddr *)&client_addr,&client_socket_len);
   int cfd = accept(sfd,(struct sockaddr *)&client_addr,&client_socket_len);
    printf("\n client connect ip is %s port is %d", inet_ntop(AF_INET,&client_addr.sin_addr.s_addr,clientip,sizeof(clientip)) ,ntohs(client_addr.sin_port));
    fflush(NULL);
   
   while (1)
   {

    read(cfd,cbuf,sizeof(cbuf));
    printf("get client data is : %s",cbuf);
    fflush(NULL);
    
   }
   

   close(sfd);

   return 0;
}